﻿using AutoMapper;
using MediatR;
using Microsoft.EntityFrameworkCore;
using RearLivestock.Common.Domains.hq;
using RearLivestock.Common.Domains.wbx;
using RearLivestock.Common.Dtos;
using RearLivestock.Common.Infrastructure.Interface;
using RearLivestock.RBAC.ErrorCodeEnum;

namespace RearLivestock.RBAC.Api.Application.hqApplication.Commands.Ablactationss
{
    public class GetAblactionsHander : IRequestHandler<GetAblactionsComand, Result>
    {
        
        private readonly IBaseRepository<Ablactations> ablactationsrepository;

        public GetAblactionsHander( IBaseRepository<Ablactations> ablactationsrepository)
        {
            
            this.ablactationsrepository = ablactationsrepository;
        }

        public async Task<Result> Handle(GetAblactionsComand request, CancellationToken cancellationToken)
        {
            

            var result = new Result() { Code = (int)CommonErrorCode.Search };
            try
            {
                var res = await (await ablactationsrepository.GetAll()).ToListAsync();
                if (res != null)
                {
                    result.Data = res;
                    result.Code = (int)CommonErrorCode.Success;
                }
            }
            catch (Exception)
            {
                result.Msg = " 猪只耳号";
            }
            return result;
        }


    }
}
